/**
 * 用户登录认证相关接口
 */

import { useMutation } from "react-query";
import { useRequest } from "../../utils/request";
import { RouteVO } from "../rbac/menu-service";

/**
 * @用户登录接口
 */
export const useLogin = () => {
  const request = useRequest<LoginUserRes>();
  return useMutation(async (params: LoginParams) => {
    const result = request("/sys/sysLogin", {
      data: params,
      method: "POST",
    });
    return result;
  });
};

/**
 * 用户登录参数
 */
export type LoginParams = {
  userName: string; //用户名称
  password: string; //用户密码
};

/**
 * 登录返回信息
 */
export type LoginUserRes = {
  token: string,
  userInfo: {
    sysId: string,
    sysName: string,
    sysPassword: string,
    createTime: string,
    updateTime: string,
    sysAvater: string | null,
    unitId: string,
    sysRoleId: number,
    phone: string,
    sysRole: {
      sysRoleId: number,
      sysRoleName: string,
      sysRolePermisstion: string,
      createTime: string,
      updateTime: string
    }
  }
  route: RouteVO[]
};
